package com.example.jiancaiwang;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;

import com.example.jiancaiwang.adapter.MyFragmentPagerAdapter;
import com.example.jiancaiwang.entity.MyTab;
import com.example.jiancaiwang.fragment.HomeFragment;
import com.example.jiancaiwang.fragment.MineFragment;
import com.example.jiancaiwang.fragment.PinPaiFragment;
import com.example.jiancaiwang.fragment.SupplyFragment;
import com.flyco.tablayout.CommonTabLayout;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private ViewPager viewPager;
    private MyFragmentPagerAdapter myFragmentPagerAdapter;
    private List<Fragment> list = new ArrayList<>();
    private CommonTabLayout commonTabLayout;
    private ArrayList<CustomTabEntity> tabEntitys = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        viewPager = findViewById(R.id.view_pager);
        list.add(new HomeFragment());
        list.add(new SupplyFragment());
        list.add(new PinPaiFragment());
        list.add(new MineFragment());
        myFragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager(),list);
        viewPager.setAdapter(myFragmentPagerAdapter);


        commonTabLayout = findViewById(R.id.common);
        tabEntitys.add(new MyTab(getString(R.string.tab_one),R.drawable.select_1,R.drawable.default_1));
        tabEntitys.add(new MyTab(getString(R.string.tab_two),R.drawable.select_2,R.drawable.default_2));
        tabEntitys.add(new MyTab(getString(R.string.tab_three),R.drawable.select_3,R.drawable.default_3));
        tabEntitys.add(new MyTab(getString(R.string.tab_four),R.drawable.select_4,R.drawable.default_4));



        commonTabLayout.setTabData(tabEntitys);
        commonTabLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {

            }

            @Override
            public void onTabReselect(int position) {

            }
        });

    }

}
